package com.ltmonitor.service.impl;

import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ltmonitor.dao.ILineSegmentDao;
import com.ltmonitor.dao.IMapAreaDao;
import com.ltmonitor.entity.LineSegment;
import com.ltmonitor.entity.MapArea;
import com.ltmonitor.service.IMapAreaService;

@Service("mapAreaService")
public class MapAreaService extends BaseService<Long, MapArea> implements IMapAreaService {

	@Autowired
	private IMapAreaDao MapAreaDao;
	

	@Autowired
	private ILineSegmentDao LineSegmentDao;
	
	@Override
	public Collection<MapArea> loadAll()
	{
		String hsql = "from MapArea where  deleted = 0";
		return this.query(hsql);
	}

	/**
	 * 保存线路 及线路下的所有线段
	 */
	public void saveRoute(MapArea ec, List<LineSegment> segments) {
		this.saveOrUpdate(ec);
		for (LineSegment ls : segments) {
			ls.setRouteId(ec.getEntityId());
		}
		LineSegmentDao.saveOrUpdateAll(segments);
	}
	/**
	 * 获取部门权限下的所有区域
	 * @param depIdList
	 * @return
	 */
	public List<MapArea> getMapAreaList(List<Long> depIdList)
	{
		String hql = "from MapArea where depId in (:depIdList) and deleted = 0";

		List<MapArea> ls = this.baseDao.queryByNamedParam(hql,
				"depIdList", depIdList.toArray());
	    return ls;
	}

}
